package com.example.gym_manage_system.view.components.panel;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;

/**
 * @author qzy
 * @description 描述
 * @create 2023-12-07 21:03
 */
public class MyPanel {
    public static JPanel imagePanel(String url, int width, int height) {
        JPanel panel = new JPanel(null);

        ImageIcon icon;
        try {
            icon = new ImageIcon(ImageIO.read(new File(url)));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        icon.setImage(icon.getImage().getScaledInstance(width, height, Image.SCALE_DEFAULT));
        JLabel label = new JLabel(icon);
        label.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight());

        panel.add(label);
        return panel;
    }
}
